package com.liuyi.netty.im.lychat.modular.caches;

import com.alicp.jetcache.anno.CacheInvalidate;
import com.alicp.jetcache.anno.CacheUpdate;
import com.alicp.jetcache.anno.Cached;
import com.liuyi.netty.im.lychat.modular.entity.MessageRecords;
import com.liuyi.netty.im.lychat.modular.service.IMessageRecordsService;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * 消息记录缓存
 *
 * @author Mr.Fmy
 * @since 2021/12/30
 */
@Service
public class MessageRecordsCache {

    @Resource
    @Lazy
    private IMessageRecordsService messageRecordsService;

    @Cached(name = "MessageRecords:", key = "'getById:'+#id", timeUnit = TimeUnit.HOURS, expire = 4)
    public MessageRecords getById(Long id) {
        return messageRecordsService.getById(id);
    }

    @CacheUpdate(name = "MessageRecords:", key = "'getById:'+#id", value = "#result")
    public MessageRecords updateById(Long id) {
        return getById(id);
    }

    @CacheInvalidate(name = "MessageRecords:", key = "'getById:'+#id")
    public void removeById(Long id) {
    }
}
